import { ref, computed, type Ref } from 'vue'
import { defineStore } from 'pinia'
import { getLoginUserUsingGet } from '@/api/userController.ts'

/**
 * 存储登录用户信息状态
 */
export const useLoginUserStore = defineStore('counter', () => {
    const loginUser = ref<API.LoginUserVO>({
    userName: '未登录',
  })


  async function fetchLoginUser() {
      const res = await getLoginUserUsingGet()
      if (res.data.code === 0 && res.data.data) {
        loginUser.value = res.data.data
      }

    // 模拟登录,3秒后登录成功
    // setTimeout(()=>{
    //   loginUser.value = {
    //     userName: "张三",
    //     id: 1
    //   }
    // },3000)
  }

  function setLoginUser(newLoginUser: any) {
    loginUser.value = newLoginUser
  }


  return { loginUser,fetchLoginUser,setLoginUser }
})
